<div class="portlet">
    <div class="portlet-actions">
        <button class="btn blue btn-sm" ng-click="grid.add()"><i class="fa fa-plus"></i> 新增</button>
    </div>
    <form class="portlet-search-body" name="queryForm">
        <input type="text" class="form-control search-item" ng-model="discountName" placeholder="名称">
        <select class="form-control search-item" ng-model="discountType"
                ng-options="opt.value as opt.name for opt in options.discounttype">
            <option value="" disabled selected hidden>-- 类型 --</option>
        </select>

        <div class="search-item">
            <button class="btn btn-sm query" ng-click="grid.query();"><i class="fa fa-search"></i> 查询</button>
            <button class="btn btn-sm reset" ng-click="grid.reset();"><i class="fa fa-eraser"></i> 重置</button>
        </div>
    </form>
    <div class="portlet-body">
        <table ed-grid class="table table-striped table-bordered table-advance table-hover"
               data-options="url: 'discount/query.do', modelText: '折扣方案', form: 'queryForm', modal: 'modal'">
            <thead>
            <tr>
                <th data-options="field: '_index'"></th>
                <th data-options="field: 'discountName'">名称</th>
                <th data-options="field: 'discountType | code : discounttype'">类型</th>
                <th data-options="field: 'amountGtThan'">订单金额达到</th>
                <th data-options="field: 'remark'">备注</th>
                <th>操作</th>
            </tr>
            </thead>
        </table>
    </div>
</div>

<div ed-modal="modal" data-options="title: '折扣方案', static: true, width: 720, defaultButton:false,onHidden:'reset'">
    <form action="#" class="form-horizontal w5c-form" w5c-form-validate novalidate name="validateForm">

        <div class="form-body">
            <div class="form-group">
                <label class="col-md-2 control-label"><span class="required">*</span>名称</label>
                <div class="col-md-4">
                    <input type="text" class="form-control" name="discountName" ng-disabled="type == '3'" ng-model="discount.discountName"
                           required>
                </div>

                <label class="col-md-2 control-label">类型</label>
                <div class="col-md-4">
                    <select class="form-control" name="discountType" ng-model="discount.discountType" ng-disabled="type == '3'" ng-change="grid.changeDiscountType()"
                            ng-options="opt.value as opt.name for opt in options.discounttype" required>
                    </select>
                </div>
            </div>
            <div class="form-group">
                <label class="col-md-2 control-label">订单金额达到</label>
                <div class="col-md-4">
                    <input type="text" class="form-control" ng-disabled="type == '3'"  ng-model="discount.amountGtThan">
                </div>

                <label class="col-md-2 control-label">备注</label>
                <div class="col-md-4">
                    <input type="text" class="form-control" ng-disabled="type == '3'" ng-model="discount.remark">
                </div>
            </div>

            <div class="card">
                <div class="card-header">
                    <h4>方案详情</h4>
                    <button ng-show="type != '3'" type="button" class="btn blue btn-sm" ng-click="grid.addDetail()"><i class="fa fa-plus"></i> 添加</button>
                </div>
                <div class="card-item" ng-repeat="discountDetail in discount.discountDetails">
                    <i ng-show="type != '3'" class="glyphicon glyphicon-trash delete" ng-click="grid.deleteDetail($index)"></i>

                    <div class="form-group" ng-show="!discount.discountType || discount.discountType == '2'">
                        <label class="col-md-2 control-label"><span class="required">*</span>开始日期</label>
                        <div class="col-md-4">
                            <input type="text" class="form-control" ed-date-picker name="startDate"
                                   ng-model="discountDetail.startDate" ng-disabled="type == '3'">
                        </div>

                        <label class="col-md-2 control-label"><span class="required">*</span>截止日期</label>
                        <div class="col-md-4">
                            <input type="text" class="form-control" ed-date-picker  name="endDate"
                                   ng-model="discountDetail.endDate" ng-disabled="type == '3'">
                        </div>
                    </div>

                    <div class="form-group" ng-show="discount.discountType == '1'">
                        <label class="col-md-2 control-label"><span class="required">*</span>累计天数</label>
                        <div class="col-md-4">
                            <input type="text" class="form-control" name="days"
                                   ng-model="discountDetail.days" ng-disabled="type == '3'">
                        </div>
                    </div>

                    <div class="form-group">
                        <label class="col-md-2 control-label"><span class="required">*</span>折扣率</label>
                        <div class="col-md-4">
                            <input type="text" class="form-control" ng-disabled="type == '3'"  name="discountRate" ng-model="discountDetail.discountRate" >
                        </div>

                        <label class="col-md-2 control-label"><span class="required">*</span>状态</label>
                        <div class="col-md-4">
                            <select class="form-control" name="discountType" ng-model="discountDetail.discountDetailStatus"
                                    ng-disabled="type == '3'" ng-options="opt.value as opt.name for opt in options.plandetailstatus" >
                            </select>
                        </div>
                    </div>
                </div>
            </div>
        </div>

        <div class="form-actions">
            <button type="button" class="btn blue" w5c-form-submit="grid.save()" ng-if="type!=3">
                <i class="fa fa-save"></i> 保存
            </button>
            <button type="button" class="btn default" ng-click="grid.cancel();" ng-if="type!=3">
                <i class="fa fa-times"></i> 取消
            </button>
            <button type="button" class="btn blue" ng-click="grid.cancel();" ng-if="type==3">
                <i class="fa fa-times"></i> 确定
            </button>
        </div>
    </form>
</div>

<!--弹出窗口：typeDetail （1：新增，2：修改） -->
<!--
<div ed-modal="detailModal"
     data-options="title: '折扣方案明细',static: true, width: 720, defaultButton:false,onHidden:'reset'">

    <form action="#" class="form-horizontal w5c-form" w5c-form-validate novalidate name="validateForm">
        <fieldset>
            <div class="form-body">
                <div class="form-group">
                    <label class="col-md-2 control-label">累积天数</label>
                    <div class="col-md-4">
                        <input type="text" class="form-control" name="days" ng-model="discountDetail.days"
                               ng-disabled="typeDetail==3" required>
                    </div>
                    <label class="col-md-2 control-label">起始日期</label>
                    <div class="col-md-4">
                        <input type="text" class="form-control" name="startDate" ng-model="discountDetail.startDate"
                               ed-date-picker data-options="format: 'yyyy-mm-dd'" ng-disabled="typeDetail==3" required>
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-md-2 control-label">截止日期</label>
                    <div class="col-md-4">
                        <input type="text" class="form-control" name="endDate" ng-model="discountDetail.endDate"
                               ed-date-picker data-options="format: 'yyyy-mm-dd'" ng-disabled="typeDetail==3" required>
                    </div>
                    <label class="col-md-2 control-label">折扣率</label>
                    <div class="col-md-4">
                        <input type="text" class="form-control" name="discountRate"
                               ng-model="discountDetail.discountRate" ng-disabled="typeDetail==3" required
                               pattern="^0\.\d*[1-9]\d*$">
                    </div>
                </div>
                <div>
                    <label class="col-md-2 control-label">备注</label>
                    <div class="col-md-4">
                        <input type="text" class="form-control" ng-model="discountDetail.remark"
                               ng-disabled="typeDetail==3">
                    </div>
                </div>
            </div>
        </fieldset>

        <div class="form-actions">
            <button type="button" class="btn blue" w5c-form-submit="detailGrid.save()">
                <i class="fa fa-save"></i> 保存
            </button>
            <button type="button" class="btn default" ng-click="detailGrid.cancel();">
                <i class="fa fa-times"></i> 取消
            </button>
        </div>

    </form>
</div>-->
